/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import da.AccountJpaController;
import entities.Account;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hung
 */
public class Login {

//    public static void main(String[] args) {
//       Account a=new Login().checkPinBank("0021001936921", "12345");
//        System.out.println(a);
//    }

    public Login() {
    }

    
 
   // private EntityManagerFactory emf = Persistence.createEntityManagerFactory("eBanking-ejbPU");

//    public EntityManager getEntityManager() {
//        return emf.createEntityManager();
//    }
  

    public Account checkPinBank(String acountCode, String pinCode) {
        String pinCode2 = EncryptMD5.getHashString(pinCode);

        AccountJpaController ajc = new AccountJpaController();
        List<Account> list = null;
        try {
            list = ajc.findAccountEntities();
            //query
            for (Account b : list) {
                if (b.getAcountCode().equals(acountCode.trim()) && b.getPinCode().equals(pinCode.trim())) {
                    return b;
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(AccountJpaController.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
}
